﻿using System;
using System.Threading.Tasks;
using FortuneUniverse.Fortune.Algorithms;

namespace FortuneUniverse.Fortune.Dyson
{
  public class PlanetAlgorithm1 : PlanetAlgorithm
  {
    public override void GenerateTerrain(double modX, double modY)
    {
      double num = 0.01;
      double num2 = 0.012;
      double num3 = 0.01;
      double num4 = 3.0;
      double num5 = -0.2;
      double num6 = 0.9;
      double num7 = 0.5;
      URandom1 urandom1 = new URandom1(this.planet.seed);
      int seed1 = urandom1.Next();
      int seed2 = urandom1.Next();
      SimplexNoise simplexNoise = new SimplexNoise(seed1);
      SimplexNoise simplexNoise2 = new SimplexNoise(seed2);
      PlanetRawData data = this.planet.data;
      Parallel.For(0, data.dataLength, (Action<int>) (i =>
      {
        double num1 = (double) data.vertices[i].x * (double) this.planet.radius;
        double num8 = (double) data.vertices[i].y * (double) this.planet.radius;
        double num9 = (double) data.vertices[i].z * (double) this.planet.radius;
        double num10 = simplexNoise.Noise3DFBM(num1 * num, num8 * num2, num9 * num3, 6) * num4 + num5;
        double num11 = simplexNoise2.Noise3DFBM(num1 * (1.0 / 400.0), num8 * (1.0 / 400.0), num9 * (1.0 / 400.0), 3) * num4 * num6 + num7;
        double num12 = num11 <= 0.0 ? num11 : num11 * 0.5;
        double num13 = num10 + num12;
        double f = num13 <= 0.0 ? num13 * 1.6 : num13 * 0.5;
        double num14 = f <= 0.0 ? Maths.Levelize2(f, 0.5) : Maths.Levelize3(f, 0.7);
        data.heightData[i] = (ushort) (((double) this.planet.radius + num14 + 0.2) * 100.0);
      }));
    }
  }
}
